package com.example.administrator.libraryclub;

import android.app.Activity;
import android.os.Bundle;

import com.fmblzf.library.inter.Listener;
import com.fmblzf.library.listview.TableListView;
import com.fmblzf.library.listview.TableListViewAdapter;
import com.fmblzf.library.listview.TextObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/11/10.
 */
public class TableListViewActivity extends Activity {


    private TableListView tl;

    private TableListViewAdapter tlva;

    private List<TextObject> mList;

    private List<TextObject> list = new ArrayList<TextObject>();

    private boolean isExpand = false;

    private Listener listener = new Listener() {
        @Override
        public Object action(int flag, Object... objs) {
            if(flag == com.example.administrator.library.R.id.iv_expand){
                if (!isExpand) {
                    if (mList != null) {
                        tlva.setmList(mList);
                    }
                }else{
                    tlva.setmList(list);
                }
                isExpand = !isExpand;
            }
            return null;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.table_listview_activity);
        initViews();
    }

    private void initViews() {
        tl = (TableListView) this.findViewById(R.id.tl);
        initDatas();
        tlva = new TableListViewAdapter(this,list);
        tl.setAdapter(tlva);
        tl.setTitles(null);
        tl.setListener(listener);

    }

    private void initDatas() {
        if(mList == null)
            mList = new ArrayList<TextObject>();
        TextObject t1 = new TextObject();
        t1.setAccount("账户1");
        t1.setCrowdCount("3");
        t1.setRelation("关系");
        t1.setRate("2%");
        mList.add(t1);
        list.add(t1);

        TextObject t2 = new TextObject();
        t2.setAccount("账户2");
        t2.setCrowdCount("4");
        t2.setRelation("关系");
        t2.setRate("3%");
        mList.add(t2);
        list.add(t2);

        TextObject t3 = new TextObject();
        t3.setAccount("账户3");
        t3.setCrowdCount("4");
        t3.setRelation("客户");
        t3.setRate("4%");
        mList.add(t3);
        list.add(t3);

        TextObject t4 = new TextObject();
        t4.setAccount("战虎2");
        t4.setCrowdCount("5");
        t4.setRelation("队里");
        t4.setRate("3%");
        mList.add(t4);
        list.add(t4);

        TextObject t5 = new TextObject();
        t5.setAccount("账户5");
        t5.setCrowdCount("7");
        t5.setRelation("奥德");
        t5.setRate("1%");
        mList.add(t5);

        TextObject t6 = new TextObject();
        t6.setAccount("账户6");
        t6.setCrowdCount("5");
        t6.setRelation("无关系");
        t6.setRate("6%");
        mList.add(t6);

        TextObject t7 = new TextObject();
        t7.setAccount("互动与");
        t7.setCrowdCount("4");
        t7.setRelation("氨基酸");
        t7.setRate("3%");
        mList.add(t7);

        TextObject t8 = new TextObject();
        t8.setAccount("aisd");
        t8.setCrowdCount("10");
        t8.setRelation("hua ad");
        t8.setRate("3%");
        mList.add(t8);
    }
}
